<!--
 * @Description: 补充账号信息
 * @Autor: zhangzhanhua
 * @Date: 2022-01-06 13:37:28
 * @LastEditors: zhangzhanhua
 * @LastEditTime: 2022-01-06 13:59:20
-->

<template>
    <div class="addOrEdit">
        <div class="elFormWeb">
            <el-form :model="form" :rules="loginFormRules" ref="loginFormRef" label-width="0" class="form_box">
                <!-- 用户名 -->
                <el-form-item prop="accNo" label="用户名" label-width="80px">
                    <el-input prefix-icon="el-icon-user" v-model="form.accNo" placeholder=""></el-input>
                </el-form-item>
                <!-- 密码 -->
                <el-form-item prop="accPwd" label="密码" label-width="80px">
                    <el-input type="password" prefix-icon="el-icon-unlock" v-model="form.accPwd" placeholder=""> </el-input>
                </el-form-item>
            </el-form>
        </div>
        <div class="userBtn">
            <el-button size="small" type="primary" @click="saveAdd">保 存</el-button>
        </div>

    </div>
</template>

<script>
export default {
    props: {
        //用户数据
        userData: {
            type: Object,
        },
    },

    data() {
        return {
            // 表单数据
            form: {
                accNo: '', //用户名
                accPwd: '', //密码
            },
            //验证规则
            loginFormRules: {
                accNo: [
                    {
                        required: true,
                        message: '请输入用户名',
                        trigger: 'blur'
                    },
                    {
                        min: 2,
                        max: 32,
                        message: '长度在 2 到 32 个字符',
                        trigger: 'blur'
                    }
                ],
                accPwd: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    {
                        min: 6,
                        max: 15,
                        message: '长度在 6 到 15 个字符',
                        trigger: 'blur'
                    }
                ],
            }
        };
    },
    mounted() {

    },
    methods: {
        /**
         * @description: 保存
         * @param {*}
         * @return {*}
         * @author: zhangzhanhua
         */
        saveAdd() {
            this.$refs.loginFormRef.validate(valid => {
                if (valid) {
                    const params = {
                        userId: this.userData.id,//用户id
                        accNo: this.form.accNo,//登录账号
                        accPwd: this.$md5(this.form.accPwd),//账号密码
                    }
                    this.$http.post(`/${this.$ServiceName}/api/external/sysuser/${this.$version}/supply_acc_no`, params).then(res => {
                        if (res.data.success) {
                            this.$message.success(res.data.msg)
                            this.$emit('supplyAccNoShowClose')
                        } else {
                            this.$message.error(res.data.msg)
                        }
                    })
                }
            })
        }
    }
};

</script>

<style lang="less" scoped>
.addOrEdit {
    .elFormWeb {
        // height: 654px;
        padding: 10px 10px 50px;
        overflow: auto;
        /deep/ .templateTree.el-tree {
            overflow: auto;
            height: 100%;
            background-color: #f5f7fa;
        }
    }
    .userBtn {
        z-index: 100;
        text-align: right;
        padding-right: 20px;
        border-top: 1px solid #c8cfde;
        background-color: #f5f7fa;
        position: absolute;
        bottom: 0px;
        left: 0;
        right: 0;
        height: 50px;
        line-height: 50px;
    }
}
</style>
